package cn.org.mrliu.ssm.aop;

import java.lang.reflect.Method;
import java.util.Arrays;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;

import cn.org.mrliu.ssm.util.cache.Cache;
import org.springframework.web.context.request.RequestContextHolder;

public class CacheAop {
	public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
		RequestContextHolder.getRequestAttributes().getSessionId();
		System.out.println("doAround....");
		//获取目标类
		Object target = pjp.getTarget();
		System.out.println(target);
		Signature signature = pjp.getSignature();
		System.out.println(signature);
		//获取目标方法
		String methodName = signature.getName();
		System.out.println(methodName);
		//获取目标方法的参数
		Object[] args = pjp.getArgs();
		System.out.println(Arrays.toString(args));

		MethodSignature methodSignature = (MethodSignature) signature;  
		System.out.println(methodSignature);
		Method method = methodSignature.getMethod();
		System.out.println(method);
		Cache cache = method.getAnnotation(Cache.class);
		System.out.println(cache);
		if (cache!=null){
			System.out.println(cache.value());
		}
		// start stopwatch
		Object retVal = pjp.proceed();
		// stop stopwatch
		return retVal;
	}
}
